﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using digit.Core;
using SMS.ServiceManager;
using SMS.UserManager;
using digit.Security;

public partial class Modules_ChangePassPage : WebControlBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!ClientState.IsAuthenticated)
        {
            Response.Redirect("~/Login.aspx?session=timeout");
        }

        this.mvMain.SetActiveView(this.vChangePass);
    }

    private bool ChangePassword()
    {
        try
        {
            return ClientState.ChangePass(ClientState.MemberInfo.Username, this.txtOldPass.Text.Trim(), Encryption.MD5Encrypt(txtNewPass.Text.Trim()));
        }
        catch (Exception ex)
        {
            this.lblError.Text = ex.Message;
            throw ex;
        }
    }

    protected void lnkChangePass_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            if (ChangePassword())
                this.mvMain.SetActiveView(vSuccess);
            else
                this.lblError.Text = "Mật khẩu cũ không đúng";
        }
        else
        {
            this.lblError.Text = "Bạn chưa nhập đầy đủ các thông tin cần thiết hoặc nhập sai, hãy kiểm tra lại";
        }
    }

    protected void lnkCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx?module=ListServiceDetail");
    }

    protected void hypHome_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx?module=ListServiceDetail");
    }
}
